//
//  RCShopManagerDataModel.m
//  RocketProject
//
//  Created by Wu Chengwei on 13-10-2.
//  Copyright (c) 2013年 Rocket. All rights reserved.
//

#import "RCShopManagerDataModel.h"
#import "FrameworkRelativeDefines.h"

@implementation RCShopManagerDetailItem

@synthesize title = _title;
@synthesize content = _content;
@synthesize field = _field;
@synthesize type = _type;

- (id) initWithDic:(NSDictionary *)dic
{
    self = [super init];
    if (self) {
        self.title = [dic stringValueForKey:@"title" defaultValue:nil operation:NSStringOperationTypeNone];
        self.content = [dic stringValueForKey:@"content" defaultValue:nil operation:NSStringOperationTypeNone];

        self.field = [dic stringValueForKey:@"field" defaultValue:nil operation:NSStringOperationTypeTrim];
        
        NSString *type = [dic stringValueForKey:@"field" defaultValue:nil operation:NSStringOperationTypeNone];
        if ([type isEqualToString:@"mobile"]) {
            self.type = kShopManagerDetailType_Phone;
        }else if([type isEqualToString:@"address"]){
            self.type = kShopManagerDetailType_Address;
        }else if([type isEqualToString:@"openhour"]){
            self.type = kShopManagerDetailType_Opentime;
        }else if([type isEqualToString:@"orderserve"]){
            self.type = kShopManagerDetailType_Character;
        }else if ([type isEqualToString:@"preferential"]){
            self.type = kShopManagerDetailType_Atmosphere;
        
        }else if ([type isEqualToString:@"description"]){
            self.type = kShopManagerDetailType_Description;
            
        }else{
            self.type = kShopManagerDetailType_Others;
        }
        
    }
    return self;
}

- (void) dealloc
{
    self.title = nil;
    self.content = nil;
    self.field = nil;
    
    [super dealloc];
}

@end

@implementation RCShopManagerDataModel

@synthesize merchantName = _merchantName;
@synthesize merchantPrice = _merchantPrice;
@synthesize merchantDetailItems = _merchantDetailItems;
@synthesize merchantImageUrl = _merchantImageUrl;
@synthesize merchantSanitation = _merchantSanitation;
@synthesize merchantScore = _merchantScore;
@synthesize merchantService = _merchantService;


- (void) dealloc
{
    self.merchantName = nil;
    self.merchantPrice = nil;
    self.merchantDetailItems = nil;
    self.merchantImageUrl = nil;
    self.merchantService = nil;
    self.merchantSanitation = nil;
    [super dealloc];
}


// 将JSON数据解析为数据模型
-(id) parseDataFromJSON:(NSDictionary*)data
{
    // 输入参数判断
    if ( nil == data )
        return nil;
    
    RCShopManagerDataModel *retObject = nil;
    retObject = [[RCShopManagerDataModel alloc] init];
    if ( nil == retObject )
        return retObject;
    
    
    NSDictionary *dataDic = [data dictionaryValueForKey:@"data" defaultValue:nil];
    
    retObject.merchantName = [dataDic stringValueForKey:@"shopname" defaultValue:nil operation:NSStringOperationTypeNone];
    retObject.merchantPrice = [dataDic stringValueForKey:@"price" defaultValue:nil operation:NSStringOperationTypeNone];
    
    retObject.merchantImageUrl = [dataDic stringValueForKey:@"picurl" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.merchantSanitation = [dataDic stringValueForKey:@"weisheng" defaultValue:nil operation:NSStringOperationTypeTrim];
    retObject.merchantScore = [dataDic intValueForKey:@"score" defaultValue:0];
    retObject.merchantService = [dataDic stringValueForKey:@"fuwu" defaultValue:nil operation:NSStringOperationTypeTrim];
    
    
    NSArray *t = [dataDic arrayValueForKey:@"items" defaultValue:nil];
    NSMutableArray *itemsArray = [[NSMutableArray alloc] init];
    for (NSDictionary *dic in t) {
        RCShopManagerDetailItem *item = [[RCShopManagerDetailItem alloc] initWithDic:dic];
        [itemsArray addObject:item];
        [item release];
    }
    

    retObject.merchantDetailItems = itemsArray;
    [itemsArray release];
    
    return [retObject autorelease];
    
}

@end
